// vue 创建公共元素组件（页头导航页脚）
Vue.component("common",{
    // json 对象语法, 反引号， 数字键1左边的那个键
    template : `
    <div>
        <div id="header" class="wrap">
    \t<img src="images/logo.gif" />
    </div>
        <div id="navbar" class="wrap">
    \t<div class="profile">
    \t\t<span v-if="myinfo">您好：{{myinfo.uname}} <a href="/demovote/user/logout">退出</a></span>
        <span v-else><a href="login.html">登录</a> <a href="register.html">注册</a></span>
    \t\t<span class="return"><a href="index.html">返回列表</a></span>
    \t\t<span class="addnew"><a href="add.html">添加新投票</a></span>
    \t</div>
    \t<div class="search">
    \t\t<form method="post" action="#">
    \t\t\t<input type="text" v-model="word" name="keywords" class="input-text" value=""/>
            <input @click.prevent="query" type="submit" name="submit" class="input-button" value="" />
    \t\t</form>
    \t</div>
    </div>
        <slot></slot>
        <div id="footer" class="wrap">
    \t源辰信息 &copy; 版权所有
    </div>
    </div>
    `,
    // props:["word"],
    data(){
        return {myinfo: null, word:""};
    },
    created(){
        axios.get("/demovote/user/myinfo").then(res=>{
            if(res.data.code==1){
                this.myinfo = res.data.data;
            } else {
                this.myinfo = null;
            }
        })
    },
    methods:{
        query(){
            // 发布 query 事件
            this.$emit("query", this.word);
        }
    }
});